/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asa;

import java.util.ArrayList;

/**
 *
 * @author scriptoff
 */
public class ASABloc extends ASAInst {
    private final ArrayList<ASAInst> instructions = new ArrayList<ASAInst>();
    private boolean isBreaked=false;

   
    public void add(ASAInst inst) {
        
        if(inst != null){
            instructions.add(inst);
            
            try {
               NeedBlocInterface nBI = (NeedBlocInterface) inst;
               nBI.setBl(this);
            } catch (ClassCastException ex) {
                
            }
        }
    }
    
    public void add(ASABloc bloc) {
        if(bloc != null && bloc.getInstructions() != null){
            for (ASAInst inst : bloc.getInstructions()) {

                try {
                    NeedBlocInterface nBI = (NeedBlocInterface) inst;
                    nBI.setBl(this);
                } catch (ClassCastException ex) {
                }
            }
            instructions.addAll(bloc.getInstructions());
            
        }
    }

    public ArrayList<ASAInst> getInstructions() {
        return instructions;
    }
    
    @Override
    public void evalue() {
        for(ASAInst inst : instructions){
            if(isBreaked)
                break;
            inst.evalue();
        }
        
    }

    @Override
    public void liberer() {
        Variables v = Variables.getInstance();
        v.deleteLocal(this);
    }

    @Override
    public String getLabelExplorateur() {
        return "BLOC";
    }

    @Override
    public ASAExpr getExpr1() {
        return null;
    }

    @Override
    public ASAExpr getExpr2() {
        return null;
    }

    void doBreak() {
        isBreaked = true;
    }

    
}
